package artid.com.arttogoa.view.pulltorefresh.pullableview;


import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

public class PullableScrollView extends ScrollView implements Pullable
{
	private OnScrollListener onScrollListener;
	public static Boolean  isSlide=true;//用来解决滑动冲突默认可以滑动
	public PullableScrollView(Context context)
	{
		super(context);
	}

	public PullableScrollView(Context context, AttributeSet attrs)
	{
		super(context, attrs);
	}

	public PullableScrollView(Context context, AttributeSet attrs, int defStyle)
	{
		super(context, attrs, defStyle);
	}

	@Override
	public boolean canPullDown()
	{
		//		Log.e("s---y", String.valueOf(getScrollY()));
		if(isSlide){
			if (getScrollY() == 0)
				return true;
			else
				return false;
		}else{
			return false;
		}
	}

	@Override
	public boolean canPullUp()
	{
		if(isSlide){
			if (getScrollY() >= (getChildAt(0).getHeight() - getMeasuredHeight()))
				return true;
			else
				return false;
		}else{
			return false;
		}
	}
	

	public void setOnScrollListener(OnScrollListener onScrollListener) {
		this.onScrollListener = onScrollListener;
	}
	
	public interface OnScrollListener{
		public void onScroll(int scrollY);
	}
	
	@Override
	protected void onScrollChanged(int l, int t, int oldl, int oldt) {
		super.onScrollChanged(l, t, oldl, oldt);
		if(onScrollListener != null){
			onScrollListener.onScroll(t);
		}
	}

}
